{extend name="base" /}
{block name="body"}
<div class="layui-body">
	<!--tab标签-->
	<div class="layui-tab layui-tab-brief">
		<ul class="layui-tab-title">
			<li class=""><a href="{:url('/admin/game')}">游戏管理</a></li>
			<li class="layui-this">添加游戏</li>
		</ul>
		<div class="layui-tab-content">
			<div class="layui-tab-item layui-show">
				<form class="layui-form form-container" action="{:url('/admin/game/save')}" method="post" enctype="multipart/form-data">
					<div class="layui-form-item">
						<label class="layui-form-label">游戏名称</label>
						<div class="layui-input-block">
							<input type="text" name="name" value="" required  lay-verify="required" placeholder="游戏名称" class="layui-input">
						</div>
					</div>

					<div class="layui-form-item">
						<label class="layui-form-label">CP名称</label>
						<div class="layui-input-block">
							<select name="gchannel" lay-search>
								<option value="0">选择CP</option>
								{foreach name=":get_cp_list()" item="vo"}
									<option value="{$vo.id}">{$vo.name}</option>
								{/foreach}
							</select>
						</div>
					</div>

					<div class="layui-form-item">
						<label class="layui-form-label">登录地址</label>
						<div class="layui-input-block">
							<input type="text" name="api_login_url" value="" required  lay-verify="required" placeholder="登录地址" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">支付通知地址</label>
						<div class="layui-input-block">
							<input type="text" name="api_pay_url" value="" required  lay-verify="required" placeholder="支付通知地址" class="layui-input">
						</div>
					</div>

					<div class="layui-form-item">
						<label class="layui-form-label">游戏背景</label>
						<div class="layui-input-block">
							<div class="layui-upload">
								<button type="button" class="layui-btn" id="uploadBgimg">上传图片</button>
								<div class="layui-upload-list">
									<img class="layui-upload-img" id="iconPreview" style="max-width: 100px; display: none;">
									<p id="uploadText"></p>
								</div>
								<input type="hidden" name="Bgimg" id="iconPath">
							</div>
						</div>
					</div>

					<div class="layui-form-item">
						<label class="layui-form-label">状态</label>
						<div class="layui-input-block">
							<input type="radio" name="gstatus" value="0" title="未上线/禁用" >
							<input type="radio" name="gstatus" value="2" title="测试中" checked="checked">
							<input type="radio" name="gstatus" value="1" title="上线">
						</div>
					</div>
					<div class="layui-form-item">
						<div class="layui-input-block">
							<button class="layui-btn" lay-submit lay-filter="*">保存</button>
							<button type="reset" class="layui-btn layui-btn-primary">重置</button>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>
{/block}
{block name="script"}
<script>
	//自定义验证规则
	;!function(){
		var layer = layui.layer
				,form = layui.form
				,upload = layui.upload;

		//上传图片
		upload.render({
			elem: '#uploadBgimg',
			url: '{:url("/admin/uploadImg")}', //改成你的上传接口
			accept: 'images',
			acceptMime: 'image/*',
			done: function(res){
				console.log(res);
				if(res.error == 0){ //上传成功
					$('#iconPreview').attr('src', res.url).show();
					$('#iconPath').val(res.url);
					$('#uploadText').html('<span style="color: #4cae4c;">上传成功</span>');
				} else {
					$('#uploadText').html('<span style="color: #ff5722;">上传失败：'+ res.msg +'</span>');
				}
			},
			error: function(){
				$('#uploadText').html('<span style="color: #ff5722;">上传失败</span>');
			}
		});

		form.verify({
			title: function(value){
				if(value.length < 2){
					return '游戏名称至少得2个字符啊';
				}
			}
			,key: [/([a-fA-F0-9]{32})$/, '密钥必须32位MD5']
			,content: function(value){
				layedit.sync(editIndex);
			}
			,letter: function(value){
				if(value.length > 1 || /[A-Z]/.test(value) == false){
					return '首字母必须大写且不能超过1个字符';
				}
			}
			,ename: function(value){
				if(!/[A-Za-z]$/.test(value)){
					return '请输入英文或拼音且不能包含数字和中文';
				}
			}
		});
	}();
</script>
{/block}